int searchCard()
{
  Serial.print("Sending scan-command: ");
  Serial.write(searchCMD, HEX);
  Serial1.write(searchCMD, 5);
  Serial.print("\n");
  
  delay(100);
  status = 0;
  while(true) {
    if (Serial1.available() > 0) {
      val = Serial1.read();
     searchRES[status] = val;
      switch (status) {
        case 0:  // parse 0xAA
          if (val == 0xAA) status = 1;
          break;
        case 1: // parse 0xBB
          if (val == 0xBB) status = 2;
          else return -1;
          break;
        case 2:
          if (val == 0x06) status = 3;
          else return -1;
          break;
        case 3:
          if (val == 0x20) status = 4;
          else return -1;
          break;
        case 4:
        case 5:
        case 6:
        case 7:
          searchRES[status - 4] = val;
          status ++;
          break;
        case 8:
          return 0; // read successfully
          break;
        default:
          return -1;
          break;
      }
     
    }
  }
}

